#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int arr[3];
int t[3];
int vis[3] = {0};
int ret[4];

int m[13] = {0,1,2,1,3,1,3,1,1,3,1,3,1};

void backtrack(int step){
	if(step == 3){
		if(t[2] - ret[1] == 18){
			if(ret[2] > t[1])	return;
			if(ret[2] == t[1] && ret[3] > t[0])	return;
		}
		cout << "YES";
		exit(0); 
	}
	
	for(int i = 0; i < 3; ++i){
		if(!vis[i]){
			if(step == 1){
				if(arr[i] >= 1 && arr[i] <= 12){
					vis[i] = 1;
					ret[step+1] = arr[i];
					backtrack(step+1);
					vis[i] = 0;
				}
			}else{
				if(m[ret[2]] == 1){
					if(arr[i] >= 1 && arr[i] <= 31){
						vis[i] = 1;
						ret[step+1] = arr[i];
						backtrack(step+1);
						vis[i] = 0;
					}
				}else if(m[ret[2]] == 3){
					if(arr[i] >= 1 && arr[i] <= 30){
						vis[i] = 1;
						ret[step+1] = arr[i];
						backtrack(step+1);
						vis[i] = 0;
					}
				}else{
					if(ret[1] % 4 == 0){
						if(arr[i] >= 1 && arr[i] <= 29){
							vis[i] = 1;
							ret[step+1] = arr[i];
							backtrack(step+1);
							vis[i] = 0;
						}
					}else{
						if(arr[i] >= 1 && arr[i] <= 28){
							vis[i] = 1;
							ret[step+1] = arr[i];
							backtrack(step+1);
							vis[i] = 0;
						}
					}
				}
			}
		}
	}
}

int main(){

	string s1,s2;
	cin >> s1 >> s2;
	
	t[0] = (s1[0] - '0') * 10 + s1[1] - '0';
	t[1] = (s1[3] - '0') * 10 + s1[4] - '0';
	t[2] = (s1[6] - '0') * 10 + s1[7] - '0';

	arr[0] = (s2[0] - '0') * 10 + s2[1] - '0';
	arr[1] = (s2[3] - '0') * 10 + s2[4] - '0';
	arr[2] = (s2[6] - '0') * 10 + s2[7] - '0';
	
	for(int i = 0; i < 3; ++i){
		
		if(t[2] - arr[i] >= 18){
			vis[i] = 1;
			ret[1] = arr[i];
			backtrack(1);
			vis[i] = 0;
		}
		
	}

	cout << "NO";

	return 0;
}

